<template>
	<scroll-view scroll-y="true" style="height: 100vh;">
		<radio-group @change="radioChange">
			<label class="itemblock" v-for="(item,index) in listdata" :key="index">
				<view>
					<!-- :checked="index === current" -->
					<radio   :value="index" style="margin: 0 20rpx;" :checked="item.def==1"/>
				</view>
				<view class="info">
					<text>{{item.realname}}-{{item.phone}}</text>
					<text class="adddefail">{{item.area}}{{item.address}}</text>
				</view>
				<navigator :url="'/pages/address/address?id='+item.id" class="editsinfo">编辑</navigator>
			</label>
		</radio-group>

		<navigator url="/pages/address/address" class="goadd">
			<text> + 新增地址</text>
		</navigator>

	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				listdata: '',
				checkeds: '',
				choiceid:'',
			}
		},
		//监听右上角事件
		onNavigationBarButtonTap() {
			if(!this.choiceid){
				this.$ShowMsg('您还没选择要发货的地址！');
				return;
			}
			uni.navigateBack({
				delta: 1
			})
		},
	
		onShow() {
			this.getinfo();
		},
		methods: {
			radioChange(evt) {
				//存储地址
				try {
					let postdata = this.listdata[evt.target.value];
					this.choiceid = postdata.id;
					uni.setStorageSync('address', postdata);
					//this.$common.state.address = postdata; 
					//this.myValue =11;
					//console.log(this.myValue)
					// this.$HttRequest({
					// 	url: '/member_addr/setDef',
					// 	param: {id:postdata.id}
					// }, 'POST').then(res => {
					// 	if (res.status === 10000) {
							
					// 	} else {
					// 		this.$ShowMsg(res.message);
					// 	}
					// }).catch(error => {
					// 	//异常错误
					// 	this.$ShowMsg('statusCode：' + error.errMsg);
					// })
				} catch (e) { 
					console.log(e);
				}
			},
			getinfo() {
				this.$HttRequest({
					url: '/member_addr/lists',
					param: ''
				}, ).then(res => {
					console.log(res);
					if (res.status === 10000) {
						this.listdata = res.data;
						res.data.map((item,index)=>{
							if(item.def==1){
								uni.setStorageSync('address', res.data[index]);
								this.choiceid = res.data[index].id;
							}
						}) 
						//console.log(uni.getStorageSync('address'));
					} else {
						this.$ShowMsg(res.message);
					}
				}).catch(error => {
					//异常错误
					this.$ShowMsg('statusCode：' + error.errMsg);
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f0f0f0;
	}

	.adddefail {
		font-size: 25rpx;
		color: #808080;
	}

	.editsinfo {
		font-size: 28rpx;
	}

	.goadd {
		color: #378aff;
		font-size: 30rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		flex: 1;
		padding: 20rpx;
	}

	.itemblock {
		height: 160rpx;
		border-bottom-color: #eaeaea;
		border-bottom-style: solid;
		border-bottom-width: 1rpx;
		background-color: #fff;
		font-size: 30rpx;
		display: flex;
		justify-content: flex-start;
		align-items: center;

		.info {
			width: 560rpx;
			padding-right: 10rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: flex-start;
		}
	}
</style>
